<?php
//lấy chi tiết bài viết
if(is_numeric($article_id) && $article_id !=-1){
	$sql = "";
	if($lang ==0){
		$sql = "SELECT vi_title as title,vi_summary as summary,vi_content as content,image,tag from tblarticle where id=$article_id and published =1";
	}else{
		$sql = "SELECT en_title as title,en_summary as summary,en_content as content,image,tag from tblarticle where id=$article_id and published =1";
	}
	
	$rs = mysql_query($sql);
	$article = mysql_fetch_object($rs);
	
	if($lang==0){
		$sql = "SELECT vi_name as name,link from tblresource where article_id = $article_id and type=1";	
	}else{
		$sql = "SELECT en_name as name,link from tblresource where article_id = $article_id and type=1";
	}

	$videos = mysql_query($sql);
	
	if($lang==0){
		$sql = "SELECT vi_name as name,link from tblresource where article_id = $article_id and type=0";	
	}else{
		$sql = "SELECT en_name as name,link from tblresource where article_id = $article_id and type=0";
	}
	
	$documents = mysql_query($sql);
	
	$numOfVideos = mysql_num_rows($videos);
	$numOfDocuments = mysql_num_rows($documents);

}else{
	if(is_numeric($section_id) && $section_id !=-1){
		$start = ($page -1 )*20; 
		
		if($lang == 0){
			$sql = "SELECT tblmenu.vi_name as name FROM tblsection inner join tblmenu on tblsection.id = tblmenu.section_id where tblsection.id =".$section_id;
		}else{
			$sql = "SELECT tblmenu.en_name as name FROM tblsection inner join tblmenu on tblsection.id = tblmenu.section_id where tblsection.id =".$section_id;
		}
		$section  = mysql_fetch_object(mysql_query($sql)); 
		if($lang == 0){
			$sql = "SELECT id,vi_title as title, created_date FROM tblarticle where section_id =".$section_id." limit ".$start.",20";
		}else{
			$sql = "SELECT id,en_title as title, created_date FROM tblarticle where section_id =".$section_id." limit ".$start.",20";
		}
	
		$listNews = mysql_query($sql);
		
		$sql = "Select id from tblarticle where  section_id =".$section_id;
		$totalNews = mysql_num_rows( mysql_query($sql));
		
	}
}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="<?php echo $article->tag;?>"/>
<title><?php echo $article->title?></title>

<link rel="stylesheet" type="text/css" href="<?php echo ROOT_PATH?>/css/cssw.css"/>
<script type="text/javascript" src="<?php echo ROOT_PATH?>/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo ROOT_PATH?>/js/sdds.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	
	$("#langvi").click(function(){
		
		$.ajax({type:"GET",
				url:"<?php echo ROOT_PATH;?>/lang.php",
				data:"lang=0",
				success: function(data){
					//alert(data);
					window.location.reload();
				}
		});
	});
	$("#langen").click(function(){
		
		$.ajax({type:"GET",
				url:"<?php echo ROOT_PATH;?>/lang.php",
				data:"lang=1",
				success: function(data){
					//alert(data);
					window.location.reload();
				}
		});
	});
});

</script>

<link rel="stylesheet" href="<?php echo ROOT_PATH?>/engine/css/videolightbox.css" type="text/css" />
<style type="text/css">
#videogallery a#videolb {
		display: none
	}
</style>

<link rel="stylesheet" type="text/css" href="<?php echo ROOT_PATH?>/engine/css/overlay-minimal.css" />
<script src="<?php echo ROOT_PATH?>/engine/js/jquery.tools.min.js" type="text/javascript"></script>
<script src="<?php echo ROOT_PATH?>/engine/js/swfobject.js" type="text/javascript"></script>
<script src="<?php echo ROOT_PATH?>/engine/js/videolightbox.js" type="text/javascript"></script>
<!-- End VideoLightBox.com HEAD section -->
<script type="text/javascript">

			function onYouTubePlayerReady(playerId) { 
			ytplayer = document.getElementById("video_overlay"); 
			ytplayer.setVolume(100); 
			} 

		</script>

</head>
<body>

<div id="page">
    	<div id="header">
        	<div id="logo">
            </div>
            <div id="language">
            	<a href="#vi" id="langvi"><img src="<?php echo ROOT_PATH?>/images/flag_vi.jpg" border="0" /></a>
            	<a href="#en" id="langen"><img src="<?php echo ROOT_PATH?>/images/flag_en.jpg" border="0"/></a>
            </div>
        </div>
        <div id="main">
        	<div id="left">
        		<!--Menu come here-->
        	<?php
        		include "menu.php"; 
        	?>
        		
            
        	 </div>
            <div id="right">
            
            	<?php
					//neu la chi tiet bai viet
					if(is_numeric($article_id) && $article_id !=-1){
				?>
            	<div id="ac">
            		<div class="title">
            			<?php echo $article->title;?>
            		</div>
            		
            		<div class="content">
            			<?php echo $article->content;?>
            		</div>	
            	</div>
            	
                <div id="sidebar">
            		<div class="aimg">
            			<?php
            				if(!empty($article->image) && $article->image!=""){
            					echo "<img src='".$article->image."' width='170px'/>";
            				} 
            			?>
            		</div>
            		<div class="summary">
            			<?php echo $article->summary;?>
            		</div>
                    
                    
                    <?php
						if($numOfVideos>0){
					?>
            		<div class="box" id="video">
                    	<div class="title">VIDEO</div>
                        <div class="content" id="videogallery">
                        	<?php
                        		while($video = mysql_fetch_object($videos)){
                        			echo "<a rel='#voverlay' href='".ROOT_PATH."/engine/swf/player.swf?url=".$video->link."&volumn=100'>".$video->name."</a>";
                        		} 
                        	?>
                        </div>
                    </div>
                    <?php }?>
                    
                    <?php
						if($numOfDocuments>0){
					?>
                    <div class="box" id="document">
                    	<div class="title"><?php echo ($lang==0)?"Tài liệu":"Document";?></div>
                    	<div class="content">
                    		<?php
                    		while($document = mysql_fetch_object($documents)){
                    			echo "<a href='$document->link'>$document->name</a>";
                    		}
                    		?>
                    	</div>
                    </div>
                    <?php }?>
            	</div>
            	
            	<?php
				}else{
				?>
					<div id="ac" style="width:87%;">
						<div class="title">
							<?php  echo $section->name;?>
						</div>
                        <ul class="list">
                        	<?php 
								while($news = mysql_fetch_object($listNews)){
									echo "<li><a href='/view/".$news->id."'>".$news->title."</a><span>".$news->created_date."</span></li>";
								}
								
							?>
                        </ul>
                        <?php
						//tao cac link phan trang
						include "pager.php";
						$pager = new Pager("/view/s/".$section_id,$page,$totalNews,20,5);
						echo $pager->getPages();
						?>
                    </div>
                <?php
				}
				?>
                
            </div>
            
        </div>
        <div id="footer">
			<div style="color:#006600;font-size:14px;font-weight:500;font-family:Arial;float:left;margin-left:60px;">
					Copyright &copy; MaxBuy Việt Nam 2010
			</div>
			
			<span class="line"></span>
			
			<div id="">
					<?php include "submenu.php";?>
			</div>
        </div>
    </div>
</div>
</body>
</html>
        	

